/**
 *
 */
package com.naiterui.ehp.bs.emr.vo.patient;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bs.emr.exception.ExceptionCodes;
import com.naiterui.ehp.bs.emr.vo.MCaseFileImgVO;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**

 * @since 2.16
 */
@SuppressWarnings("WeakerAccess")
@ApiModel(value = "CaseFileVO", description = "患者病例VO")
public class CaseFileVO {

    private static final Logger LOGGER = LoggerFactory.getLogger(CaseFileVO.class);

    @ApiModelProperty(value = "病例id")
    private String caseId;
    /**
     * 医院id：<code>hospitalId</code>
     */
    @ApiModelProperty(value = "医院id")
    private Integer hospitalId;
    /**
     * 医院名：<code>hosptital</code>
     */
    @ApiModelProperty(value = "医院名")
    @JsonProperty("hospital")
    private String hospitalName;
    /**
     * 科室id：<code>departmentId</code>
     */
    @ApiModelProperty(value = "科室id")
    private Integer departmentId;
    /**
     * 科室：<code>department</code>
     */
    @ApiModelProperty(value = "科室")
    @JsonProperty("department")
    private String departmentName;
    /**
     * 医生名：<code>doctor</code>
     */
    @ApiModelProperty(value = "医生名")
    @JsonProperty("doctor")
    private String doctorName;
    /**
     * 问诊时间 毫秒值：<code>vistingTime</code>
     */
    @ApiModelProperty(value = "问诊时间 毫秒值")
    private Long vistingTime;

    /**
     * 医嘱图片列表：<code>adviceList</code>
     */
    @ApiModelProperty(value = "医嘱图片列表")
    private List<MCaseFileImgVO> adviceList = new ArrayList<>();
    /**
     * 处方单图片列表：<code>prescriptionList</code>
     */
    @ApiModelProperty(value = "处方单图片列表")
    private List<MCaseFileImgVO> prescriptionList = new ArrayList<>();
    /**
     * 检验单图片列表：<code>checkList</code>
     */
    @ApiModelProperty(value = "检验单图片列表")
    private List<MCaseFileImgVO> checkList = new ArrayList<>();

    /**
     * 校验病例参数
     * PatientCaseServiceImpl.validCaseParam()
     *
     *
     * @throws BusinessException

     * @Date 2018年6月1日
     * @since 2.18
     */
    public void validCaseParam() throws BusinessException {
        // 上传图片url不可为空
        if (!this.validateImgUrl()) {
            LOGGER.error("patient case save ERROR ; data imgs imgUrl is null : data {}", this);
            throw new BusinessException(ExceptionCodes.INVALID_REQUEST);
        }
        // 上传图片必填上传时间
        if (!this.validateUploadtime()) {
            LOGGER.error("patient case save ERROR ; data imgs uploadTime is null : data {}", this);
            throw new BusinessException(ExceptionCodes.CASE_IMG_UPLOADTIME_IS_NULL);
        }
    }

    /**
     * 校验图片上传url PatientCaseController.validateImgUrl()<BR> <P>Author : Gaoll
     * </P> <P>Date : 2015年9月29日 </P>
     */
    private boolean validateImgUrl() {

        boolean passFlag = true;
        for (MCaseFileImgVO tempImg : this.getAdviceList()) {
            if (null != tempImg && StringUtils.isEmpty(tempImg.getImgUrl())) {
                passFlag = false;
            }
        }
        for (MCaseFileImgVO tempImg : this.getCheckList()) {
            if (null != tempImg && StringUtils.isEmpty(tempImg.getImgUrl())) {
                passFlag = false;
            }
        }
        for (MCaseFileImgVO tempImg : this.getPrescriptionList()) {
            if (null != tempImg && StringUtils.isEmpty(tempImg.getImgUrl())) {
                passFlag = false;
            }
        }
        return passFlag;
    }

    /**
     * 校验图片上传时间是否通过 PatientCaseController.validateUploadtime()<BR> <P>Author :
     * Gaoll </P> <P>Date : 2015年9月23日 </P>
     */
    private boolean validateUploadtime() {

        boolean passFlag = true;
        for (MCaseFileImgVO tempImg : this.getAdviceList()) {
            if (null != tempImg && null == tempImg.getUploadTime()) {
                passFlag = false;
            }
        }
        for (MCaseFileImgVO tempImg : this.getCheckList()) {
            if (null != tempImg && null == tempImg.getUploadTime()) {
                passFlag = false;
            }
        }
        for (MCaseFileImgVO tempImg : this.getPrescriptionList()) {
            if (null != tempImg && null == tempImg.getUploadTime()) {
                passFlag = false;
            }
        }
        return passFlag;
    }

    public String getCaseId() {
        return this.caseId;
    }

    public void setCaseId(String caseId) {
        this.caseId = caseId;
    }

    public Integer getHospitalId() {
        return this.hospitalId;
    }

    public void setHospitalId(Integer hospitalId) {
        this.hospitalId = hospitalId;
    }

    public String getHospitalName() {
        return this.hospitalName;
    }

    public void setHospitalName(String hospitalName) {
        this.hospitalName = hospitalName;
    }

    public Integer getDepartmentId() {
        return this.departmentId;
    }

    public void setDepartmentId(Integer departmentId) {
        this.departmentId = departmentId;
    }

    public String getDepartmentName() {
        return this.departmentName;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }

    public String getDoctorName() {
        return this.doctorName;
    }

    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }

    public Long getVistingTime() {
        return this.vistingTime;
    }

    public void setVistingTime(Long vistingTime) {
        this.vistingTime = vistingTime;
    }

    public List<MCaseFileImgVO> getAdviceList() {
        return this.adviceList;
    }

    public void setAdviceList(List<MCaseFileImgVO> adviceList) {
        this.adviceList = adviceList;
    }

    public List<MCaseFileImgVO> getPrescriptionList() {
        return this.prescriptionList;
    }

    public void setPrescriptionList(List<MCaseFileImgVO> prescriptionList) {
        this.prescriptionList = prescriptionList;
    }

    public List<MCaseFileImgVO> getCheckList() {
        return this.checkList;
    }

    public void setCheckList(List<MCaseFileImgVO> checkList) {
        this.checkList = checkList;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

}
